import time

from pom.base import BaseDriver
from pom.login.account_login_page import AccountLogin
from pom.login.systemloginpage import LoginPage
from pom.Admin.MainPage import AdminMainPage

class Login(BaseDriver):

    def __init__(self, driver):
        super(Login, self).__init__(driver)
        self.accountlogin = AccountLogin(driver)
        self.systemlogin = LoginPage(driver)
        self.mainmodel = AdminMainPage(driver)


    def account_login(self, name, passwd):
        self.accountlogin.login_link.click()
        self.accountlogin.username.send_keys(name)
        self.accountlogin.passwd.send_keys(passwd)
        self.accountlogin.login_btn.click()

# 返回 alert 框中的文字
    def account_login_fail(self, name, passwd):
        self.accountlogin.login_link.click()
        self.accountlogin.username.send_keys(name)
        self.accountlogin.passwd.send_keys(passwd)
        self.accountlogin.login_btn.click()
        # time.sleep(0.5)
        return self.accountlogin.fail_alert.text



    def system_login(self, name, passwd):
        self.systemlogin.loginname.send_keys(name)
        self.systemlogin.loginpass.send_keys(passwd)
        self.systemlogin.loginbtn.click()



    def logined_name(self):
        return self.mainmodel.username.text
